# display .......

import pygame
import common
import towers
import bullet

class Window:
    def __init__(self,screen):
        self.screen = screen
        self.img_bg = common.images['map']
        pygame.display.set_caption('Tower Defense 101')
        self.bgcolor = (100,70,70)
        
    def update(self,tpos,twr_list,crp_list,ui,active_obj):
        self.screen.blit(self.img_bg,(0,0))
        tx,ty = tpos
        
             
        for tower in twr_list:
            self.screen.blit(tower.image,(tower.x+tower.x_offset, tower.y+tower.y_offset))
            if tower.selected == True:
                pygame.draw.circle(self.screen,(255,255,255),(tower.x,tower.y),tower.sight, 1)
           
            for bullet in tower.bulletlist:
                bullet.update()
                self.screen.blit(bullet.image,(bullet.x+bullet.x_offset,bullet.y+bullet.y_offset))
                if bullet.hit_test():
                    tower.bulletlist.remove(bullet)
        for creep in crp_list:
            self.screen.blit(creep.image,(creep.x+creep.x_offset, creep.y+creep.y_offset))
            self.screen.fill((255,100,100), creep.hpRect)            
        self.screen.fill((100,100,100),(ui.x,0,ui.WIDTH,608))            
        
        for obj in ui.elements:
            if obj.elem_type == 'box':
                self.screen.blit(obj.image,(obj.x,obj.y))
                if obj.elements <> None:
                    for elem in obj.elements:
                        self.screen.blit(elem.image,(elem.x,elem.y))
                        
            if obj.elem_type == 'button':
                self.screen.blit(obj.image,(obj.x,obj.y))
            
        if active_obj <> None:
            self.screen.blit(active_obj.ghost,(tx,ty))
            
        pygame.display.flip()
        